﻿Imports QLTHUVIEN.BUS
Imports QLTHUVIEN.DAO
Imports QLTHUVIEN.DTO

Public Class frmBoPhan
    Public Sub layDanhSach()
        Dim BoPhanBus As BoPhanBUS = New BoPhanBUS()
        Dim data As DataTable = BoPhanBus.LayDanhSach()
        dtgDanhSachBoPhan.DataSource = data
    End Sub

    Private Sub frmBoPhan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        layDanhSach()
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        If txtTenBoPhan.Text = "" Then
            Return
        End If

        Dim BoPhanDto As New BoPhanDTO()
        BoPhanDto.TenBoPhan = txtTenBoPhan.Text

        Dim bpBus As New BoPhanBUS()
        bpBus.ThemBoPhan(BoPhanDto)

        layDanhSach()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        If txtTenBoPhan.Text = "" Or txtMaBoPhan.Text = "" Then
            Return
        End If

        Dim BoPhanDto As New BoPhanDTO()
        BoPhanDto.MaBoPhan = txtMaBoPhan.Text
        BoPhanDto.TenBoPhan = txtTenBoPhan.Text

        Dim bpBus As New BoPhanBUS()
        bpBus.SuaBoPhan(BoPhanDto)

        layDanhSach()
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        Dim BoPhanDto As New BoPhanDTO()
        BoPhanDto.MaBoPhan = txtMaBoPhan.Text
        BoPhanDto.TenBoPhan = txtTenBoPhan.Text
        BoPhanDto.IsDelete = True

        Dim bcBus As New BoPhanBUS()
        bcBus.XoaBoPhan(BoPhanDto)

        layDanhSach()
    End Sub

    Private Sub dtgDanhSachBoPhan_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtgDanhSachBoPhan.CellClick
        txtMaBoPhan.Text = dtgDanhSachBoPhan.CurrentRow.Cells(0).Value.ToString()
        txtTenBoPhan.Text = dtgDanhSachBoPhan.CurrentRow.Cells(1).Value.ToString()
    End Sub
End Class